home *** CD-ROM | disk | FTP | other *** search
- /* Small Systems Guild */
- /* PO box 2751 */
- /* 3105 Sunnywood */
- /* Ann Arbor, Michigan 48103 */
- /* (313) 996-4238 */
-
- /* copyright © 1987 Small Systems Guild */
-
- /* source code compilable using */
- /* Lightspeed C compiler 2.01 */
-
- #include "objectMgr.h"
-
- Handle Window(sel,arg)
- USHORT sel;
- ULONG arg;
- {
- switch(sel) {
- case NEW: /* MUST be unique for each subclass */
- return(new_window(arg));
- break;
- case SELF:
- return(self_object(arg));
- break;
- case CLASS:
- return(class_object(arg));
- break;
- case SIZE:
- return(size_object(arg));
- break;
- case ASK_STATUS:
- return(ask_object(arg));
- break;
- case SET_STATUS:
- return(set_object(arg));
- break;
- case VALID:
- return(valid_object(arg));
- break;
- case SHOW:
- return(show_window(arg));
- break;
- case HIDE:
- return(hide_window(arg));
- break;
- case ACTIVATE:
- return(actv_window(arg));
- break;
- case DEACTIVATE:
- return(deactv_window(arg));
- break;
- case MOVE:
- return(move_window(arg));
- break;
- case GROW:
- return(grow_window(arg));
- break;
- case UPDATE:
- return(updt_window(arg));
- break;
- case FREE:
- return(free_window(arg));
- break;
- default:
- return(NULL);
- }
- }
-
- Handle new_window(arg)
- WDHandle arg;
- {
- Handle objHndl;
- ULONG size;
- WindowPtr wPtr;
-
- if (!ValidHandle((Handle)arg))
- return(NULL);
-
- size = (ULONG)sizeof(window);
- objHndl = NewHandle(size);
- if (!ValidHandle(objHndl))
- return(NULL);
-
- wPtr = crt_window(arg);
- if (!ValidPointer((Ptr)wPtr)) {
- DisposHandle(objHndl);
- return(NULL);
- }
-
- (**((object **)objHndl)).isa = WINDOW;
- (**((object **)objHndl)).size = size;
- (**((object **)objHndl)).status = INACTIVE;
- (**((object **)objHndl)).sync = OBJ_SYNC;
- (**((object **)objHndl)).id = objHndl;
- (**((window **)objHndl)).wPtr = wPtr;
- return(objHndl);
- }
-
- Handle show_window(objHndl)
- Handle objHndl;
- {
- if (!ValidHandle(objHndl))
- return(NULL);
-
- if ((**((object **)objHndl)).status != ACTIVE)
- return(NULL);
-
- if (!ValidPointer((Ptr)((**((window **)objHndl)).wPtr)))
- return(NULL);
-
- ShowWindow((**((window **)objHndl)).wPtr);
- return(objHndl);
- }
-
- Handle hide_window(objHndl)
- Handle objHndl;
- {
- if (!ValidHandle(objHndl))
- return(NULL);
-
- if ((**((object **)objHndl)).status != ACTIVE)
- return(NULL);
-
- if (!ValidPointer((Ptr)((**((window **)objHndl)).wPtr)))
- return(NULL);
-
- HideWindow((**((window **)objHndl)).wPtr);
- return(objHndl);
- }
-
- Handle actv_window(objHndl)
- Handle objHndl;
- {
- WData WD;
- WindowPtr wPtr;
-
- if (!ValidHandle(objHndl))
- return(NULL);
-
- wPtr = (**((window **)objHndl)).wPtr;
- if (!ValidPointer((Ptr)wPtr))
- return(NULL);
-
- GetWData(wPtr,&WD);
- if (ValidWData(&WD)) {
- SetPort(wPtr);
- if (WD.GrowBox)
- DrawGrowIcon(wPtr);
- if (ValidHandle((Handle)(WD.vScrollBar)))
- ShowControl(WD.vScrollBar);
- if (ValidHandle((Handle)(WD.hScrollBar)))
- ShowControl(WD.hScrollBar);
- if (ValidHandle((Handle)(WD.wList)))
- LMActivate(WD.wList);
- if (ValidHandle((Handle)(WD.TEH)))
- TEActivate(WD.TEH);
- return(objHndl);
- }
- return(NULL);
- }
-
- Handle deactv_window(objHndl)
- Handle objHndl;
- {
- WData WD;
- WindowPtr wPtr;
-
- if (!ValidHandle(objHndl))
- return(NULL);
-
- wPtr = (**((window **)objHndl)).wPtr;
- if (!ValidPointer((Ptr)wPtr))
- return(NULL);
-
- GetWData(wPtr,&WD);
- if (ValidWData(&WD)) {
- if (WD.GrowBox)
- DrawGrowIcon(wPtr);
- if (ValidHandle((Handle)(WD.vScrollBar)))
- HideControl(WD.vScrollBar);
- if (ValidHandle((Handle)(WD.hScrollBar)))
- HideControl(WD.hScrollBar);
- if (ValidHandle((Handle)(WD.wList)))
- LMDeactivate(WD.wList);
- if (ValidHandle((Handle)(WD.TEH)))
- TEDeactivate(WD.TEH);
- return(objHndl);
- }
- return(NULL);
- }
-
- Handle move_window(argHndl)
- Handle argHndl;
- {
- Handle objHndl;
- WindowPtr wPtr;
- SHORT hCoord,vCoord;
-
- if (!ValidPointer((Ptr)argHndl))
- return(NULL);
-
- objHndl = ((msgArgs *)argHndl)->objHndl;
- if (ValidHandle(objHndl)) {
- if (!((**((object **)objHndl)).sync == OBJ_SYNC)) {
- objHndl = argHndl;
- if (!((**((object **)objHndl)).sync == OBJ_SYNC))
- return(NULL);
- }
- }
- else {
- objHndl = argHndl;
- if (!((**((object **)objHndl)).sync == OBJ_SYNC))
- return(NULL);
- }
-
- wPtr = (**((window **)objHndl)).wPtr;
- hCoord = (SHORT)(((msgArgs *)argHndl)->objDat1);
- vCoord = (SHORT)(((msgArgs *)argHndl)->objDat2);
- if (!ValidPointer((Ptr)wPtr))
- return(NULL);
-
- MoveWindow(wPtr,hCoord,vCoord,FALSE);
- return(objHndl);
- }
-
- Handle grow_window(argHndl)
- Handle argHndl;
- {
- WData WD;
- Handle objHndl;
- WindowPtr wPtr;
- SHORT hCoord,vCoord;
- Rect newRect,badRect,oldWRect;
-
- if (!ValidPointer((Ptr)argHndl))
- return(NULL);
-
- objHndl = ((msgArgs *)argHndl)->objHndl;
- if (ValidHandle(objHndl)) {
- if (!((**((object **)objHndl)).sync == OBJ_SYNC)) {
- objHndl = argHndl;
- if (!((**((object **)objHndl)).sync == OBJ_SYNC))
- return(NULL);
- }
- }
- else {
- objHndl = argHndl;
- if (!((**((object **)objHndl)).sync == OBJ_SYNC))
- return(NULL);
- }
-
- wPtr = (**((window **)objHndl)).wPtr;
- hCoord = (SHORT)(((msgArgs *)argHndl)->objDat1);
- vCoord = (SHORT)(((msgArgs *)argHndl)->objDat2);
- if (!ValidPointer((Ptr)wPtr))
- return(NULL);
-
- GetWData(wPtr,&WD);
- if (!ValidWData(&WD))
- return(NULL);
-
- oldWRect = wPtr->portRect;
- EraseRect(&oldWRect);
- if (WD.GrowBox) {
- newRect = oldWRect;
- ClipRect(&newRect);
- newRect.left = newRect.right - 14;
- newRect.top = newRect.bottom - 14;
- }
-
- SizeWindow(wPtr,hCoord,vCoord,TRUE);
-
- if (WD.GrowBox) {
- if (!ValidHandle((Handle)(WD.vScrollBar))) {
- badRect = oldWRect;
- badRect.left = badRect.right - 15;
- InvalRect(&badRect);
- }
- if (!ValidHandle((Handle)(WD.hScrollBar))) {
- badRect = oldWRect;
- badRect.top = badRect.bottom - 15;
- InvalRect(&badRect);
- }
- }
-
- if (ValidHandle((Handle)(WD.TEH)))
- TEResize(wPtr,&oldWRect);
- ClipRect(&(wPtr->portRect));
- InvalRect(&newRect);
- AdjustScrollBars(wPtr);
- return(objHndl);
- }
-
- Handle updt_window(objHndl)
- Handle objHndl;
- {
- WData WD;
- GrafPtr savePort;
- Rect upRect;
- WindowPtr wPtr;
-
- if (!ValidHandle(objHndl))
- return(NULL);
-
- if ((**((object **)objHndl)).status != ACTIVE)
- return(NULL);
-
- wPtr = (**((window **)objHndl)).wPtr;
- if (!ValidPointer((Ptr)wPtr))
- return(NULL);
-
- GetWData(wPtr,&WD);
- if (ValidWData(&WD)) {
- GetPort(&savePort); /* save current GrafPort */
- SetPort(wPtr); /* connect QuickDraw to window */
- BeginUpdate(wPtr);
- upRect = wPtr->portRect;
- ClipRect(&upRect);
- if (ValidHandle((Handle)(WD.hScrollBar)))
- upRect.bottom -= 15;
- if (ValidHandle((Handle)(WD.vScrollBar)))
- upRect.right -= 15;
- EraseRect(&upRect);
-
- if (ValidHandle((Handle)WD.windowPic)) {
- CalcContentRect(wPtr,&upRect);
- GrafUpdate(wPtr,&upRect);
- }
-
- if (ValidHandle((Handle)(WD.wList)))
- LMUpdate(wPtr,WD.wList);
-
- if (ValidHandle((Handle)(WD.TEH))) {
- XTTEUpdate(wPtr);
- if (wPtr == FrontWindow())
- TEActivate(WD.TEH);
- else
- TEDeactivate(WD.TEH);
- }
-
- DrawControls(wPtr);
- if (WD.GrowBox)
- DrawGrowIcon(wPtr);
- EndUpdate(wPtr);
- SetPort(savePort); /* restore original GrafPort */
- return(objHndl);
- }
- else
- return(NULL);
- }
-
- Handle free_window(objHndl)
- Handle objHndl;
- {
- if (!ValidHandle(objHndl))
- return(objHndl);
-
- if ((**((object **)objHndl)).status == ACTIVE)
- return(objHndl);
-
- if ((**((object **)objHndl)).isa != WINDOW)
- return(objHndl);
-
- KillWindow((**((window **)objHndl)).wPtr);
- DisposHandle(objHndl);
- return(NULL);
- }
-
- WindowPtr crt_window(wdh)
- WDHandle wdh;
- {
- WData WD;
- WDHandle tempWDH;
- WindowPtr oldFrontW,wrPtr;
- WindowRecord *wRecPtr;
- Rect boundsRect;
- int wType;
- char *title;
- Boolean goAwayBox;
- Boolean Visible;
-
- boundsRect = *((Rect *)((**wdh).rsrv3));
-
- wType = (SHORT)((**wdh).rsrv4);
- if ((wType < 0) || (wType > 23) ||
- ((wType > 4) && (wType < 16) && (wType != 8) && (wType != 12)))
- return(NULL);
- /* make conflicting window types consistent */
- if (((**wdh).GrowBox == FALSE) && (wType == 0))
- wType = 4;
- if (((**wdh).GrowBox != FALSE) && (wType == 4))
- wType = 0;
- if (((**wdh).GrowBox == FALSE) && (wType == 8))
- wType = 12;
- if (((**wdh).GrowBox != FALSE) && (wType == 12))
- wType = 8;
-
- oldFrontW = FrontWindow();
-
- wRecPtr = (WindowRecord *)((**wdh).rsrv1);
- title = (char *)((**wdh).rsrv2);
- goAwayBox = (Boolean)((**wdh).UsrRef2);
- Visible = (Boolean)((**wdh).UsrRef1);
- wrPtr = NewWindow(wRecPtr,&boundsRect,title,FALSE,wType,NEG_ONE,goAwayBox,NULL);
- if (!ValidPointer((Ptr)wrPtr))
- return(NULL);
-
- InitWData(&WD);
- WD.GrowBox = (**wdh).GrowBox;
- if (WD.GrowBox)
- DrawGrowIcon(wrPtr);
- if ((**wdh).vScrollBar != NULL) {
- boundsRect.left = wrPtr->portRect.right - XTBarWidth;
- boundsRect.top = wrPtr->portRect.top - 1;
- boundsRect.right = wrPtr->portRect.right + 1;
- boundsRect.bottom = wrPtr->portRect.bottom - wrPtr->portRect.top;
- if (WD.GrowBox)
- boundsRect.bottom -= 14;
- WD.vScrollBar = NewControl(wrPtr,&boundsRect,"\P",Visible,1,1,100,scrollBarProc,NULL);
- }
- if ((**wdh).hScrollBar != NULL) {
- boundsRect.left = wrPtr->portRect.left - 1;
- boundsRect.top = wrPtr->portRect.bottom - XTBarWidth;
- boundsRect.right = wrPtr->portRect.right;
- if (WD.GrowBox || (**wdh).vScrollBar != NULL)
- boundsRect.right -= 14;
- boundsRect.bottom = wrPtr->portRect.bottom + 1;
- WD.hScrollBar = NewControl(wrPtr,&boundsRect,"\P",Visible,1,1,100,scrollBarProc,NULL);
- }
- tempWDH = (WDHandle)NewHandle((long)sizeof(WData));
- SetWRefCon(wrPtr,tempWDH);
- if (!ValidHandle((Handle)tempWDH))
- return(NULL);
- (**tempWDH).sync1 = SYNC1VAL;
- (**tempWDH).sync2 = SYNC2VAL;
- SetWData(wrPtr,&WD);
-
- DisposHandle(wdh);
- if (!Visible)
- return(wrPtr);
-
- ShowWindow(wrPtr);
- SetPort(wrPtr);
- SelectWindow(wrPtr);
-
- if (ValidPointer((Ptr)oldFrontW)) {
- GetWData(oldFrontW,&WD);
- if (ValidWData(&WD)) {
- if (WD.GrowBox)
- DrawGrowIcon(oldFrontW);
- if (ValidHandle((Handle)(WD.vScrollBar)))
- HideControl(WD.vScrollBar);
- if (ValidHandle((Handle)(WD.hScrollBar)))
- HideControl(WD.hScrollBar);
- }
- }
- return(wrPtr);
- }
-
- WDHandle setup_WData(wrPtr,wRect,Title,wType,Visible,GoAwayBox,GrowBox,vScrollBar,hScrollBar)
- WindowRecord *wrPtr;
- Rect *wRect;
- char *Title;
- int wType;
- Boolean Visible,GoAwayBox,GrowBox,vScrollBar,hScrollBar;
- {
- WDHandle wdh;
-
- wdh = (WDHandle)NewHandle((LONG)sizeof(WData));
- InitWData(*wdh);
-
- (**wdh).rsrv1 = (ULONG)wrPtr;
- (**wdh).rsrv3 = (ULONG)wRect;
- (**wdh).rsrv2 = (ULONG)Title;
- (**wdh).rsrv4 = (ULONG)wType;
-
- (**wdh).UsrRef1 = (ULONG)Visible;
- (**wdh).UsrRef2 = (ULONG)GoAwayBox;
- (**wdh).GrowBox = GrowBox;
- (**wdh).vScrollBar = (ControlHandle)vScrollBar;
- (**wdh).hScrollBar = (ControlHandle)hScrollBar;
-
- return(wdh);
- }
-
-